import json
import urllib.request as ur
import urllib.parse as up
# import requests
# requset = ur.Request('https://edu.csdn.net/')
# response = ur.urlopen(requset).read()
# with open('test.html','wb') as f:
#     f.write(response)


# data  = {
#     'kw':'美剧',
#     'ie':'utf-8',
#     'pn':'50'
# }
# urldata =up.urlencode(data)
# request = ur.Request('https://tieba.baidu.com/f?'+urldata)
# response = ur.urlopen(request).read()
# with open('test1.html','wb') as f:
#     f.write(response)

# 'https://fanyi.baidu.com/sug',
data = {
    'kw':'python'
}
urldata = up.urlencode(data)
print(type(urldata))
request = ur.Request(
    url='https://fanyi.baidu.com/sug',
    data=urldata.encode('utf-8')
)
response = ur.urlopen(request).read()
with open('test2.heml','wb') as f:
    f.write(response)

#字典转json
print(json.loads(response))